#include "vocabulary.h"

namespace WordMemory
{
    Vocabulary::Vocabulary(int id, int userId, const QString &name,
                           int wordCount, bool isDefault, bool isFavorites, bool isMistakesBook)
        : id(id)
        , userId(userId)
        , name(name)
        , wordCount(wordCount)
        , isDefault(isDefault)
        , isFavorites(isFavorites)
        , isMistakesBook(isMistakesBook)
    {}

    QJsonObject Vocabulary::toJson() const
    {
        QJsonObject json;
        json["id"] = id;
        json["user_id"] = userId;
        json["name"] = name;
        json["word_count"] = wordCount;
        json["is_default"] = isDefault;
        json["is_favorites"] = isFavorites;
        json["is_mistakes_book"] = isMistakesBook;
        return json;
    }

    Vocabulary Vocabulary::fromJson(const QJsonObject &json)
    {
        return Vocabulary(
            json["id"].toInt(),
            json["user_id"].toInt(),
            json["name"].toString(),
            json["word_count"].toInt(0),
            json["is_default"].toBool(false),
            json["is_favorites"].toBool(false),
            json["is_mistakes_book"].toBool(false));
    }
}

